package graphics;

import javax.swing.JToggleButton;
import javax.swing.ImageIcon;

import java.awt.Color;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import java.util.Observable;
import java.util.Observer;

import java.awt.*;

import model.building.Building;

public class GBuilding extends JToggleButton implements Observer, GStatusArea.Viewer {

    /** Attributs */
    private Building m_building;
    private ImageIcon m_sprite;
    private Component m_gStatusAreaViewer;
    
    /** Constructeurs */
    public GBuilding(Building building, Component gStatusAreaViewer) {
        super(building.getName());
        m_building = building;
        m_gStatusAreaViewer = gStatusAreaViewer;
        m_sprite = null;
    }
    public GBuilding(Building building, Component gStatusAreaViewer, ImageIcon sprite) {
        super(sprite);
        setOpaque(false);
        setBackground(new Color(0,0,0,0));
        m_gStatusAreaViewer = gStatusAreaViewer;
        m_building = building;
        m_sprite = sprite;
        addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent e) 
                { setIcon(new ImageIcon(m_sprite.getImage().getScaledInstance(getWidth(), getHeight(), 0))); }
            });
    }

    /** Accesseurs */
    public Building getBuilding() 
    { return m_building; }

    /** Methodes */
    public void update(GStatusArea gStatusArea) 
    { gStatusArea.setInfo(m_building.getName(), m_gStatusAreaViewer); }

    public void update(Observable building, Object arg) 
    { throw new RuntimeException("ToDo"); }

}